<template>
  <view class="content" :style="{ paddingTop: statusBarHeight + 'px' }">
    <uni-nav-bar title="非标商品搜索" fixed :border="false" height="88rpx" background-color="#f7f7f7" left-icon="left"
      @clickLeft="onClickLeft"></uni-nav-bar>
    <view class="topCard">
      <uni-search-bar v-model="name" radius="100" placeholder="请输入" cancelButton="none"
        style="flex: 1;margin: 0;padding: 0;margin-right: 20rpx;vertical-align: baseline !important;line-height: 50rpx !important;"
        @confirm="searchFn" @clear="clearFn" />
      <view class="searchBtn" @click="searchFn">搜索</view>
    </view>
    <scroll-view class="scroll-view_H" scroll-y @refresherrefresh="refresherrefreshFn" refresher-enabled="true"
      :show-scrollbar="false" @scrolltolower="lower" :refresher-triggered="triggered" enhanced
      style="height: calc(100% - var(--window-top) - 168rpx);">
      <view class="goodCard" v-for="item in goodsList" :key="item.id">
        <image :src="item.imgUrl ? item.imgUrl : '/static/index/noneImg.png'" mode="aspectFill" class="goodsImg">
        </image>
        <view class="goodInfo">
          <view class="goodsname u-ellipsis">{{ item.name }}</view>
          <view class="sub_title">进价：{{ item.outboundPrice }}元</view>
          <view class="flexBox">
            <text class="txt">配送规格：{{ item.deliveryNorms }}KG</text>
          </view>
          <view class="flexBox">
            <text class="txt" v-if="item.status == '0'">状态：正常</text>
            <text class="txt" v-if="item.status == '1'">状态：停用</text>
            <text class="txt" v-if="item.status == '2'">状态：淘汰</text>
            <view class="btnBox" @click="addPointPurchase(item.id)" v-if="item.status == '0'">点采</view>
          </view>
        </view>
      </view>
      <uni-load-more :status="loading" v-if="goodsList.length > 0"></uni-load-more>
      <view
        style="width: 100%;height: 100%;background-color: #f7f7f7;display: flex;justify-content: center;align-items: center;"
        v-if="goodsList.length == 0">
        <image src="/static/index/nonedata.png" mode="aspectFill" style="width: 400rpx;height: 400rpx;"></image>
      </view>
    </scroll-view>

    <cls-DragBtn is-dock :bottom-px="250" @btnClick="dianCaiclick">
      <view class="floatBox btn type-1">点采</view>
    </cls-DragBtn>
  </view>
</template>

<script>
import { getNonstandardCommodityLists, reqAddPointPurchase } from '@/apis/member.js'
export default {
  name: "InventoryInfo",
  data() {
    return {
      goodsList: [], // 供应链标品
      page: {
        pageNum: 1,
        pageSize: 7
      },
      type: '',
      name: '',
      triggered: false, // 是否触发下拉刷新
      loading: 'loading', // 是否触发上拉加载
    }
  },
  onLoad(params) {
    this.type = params.type
    console.log('111', this.type);
    // this.getNonstandardCommodityLists()
  },
  onShow() {
  },
  methods: {
    refresherrefreshFn() {
      console.log('233333');
      this.page.pageNum = 1
      this.triggered = true
      this.goodsList = []
      this.loading = "loading";
      this.getNonstandardCommodityLists()
    },
    // 供应链 
    async getNonstandardCommodityLists() {
      const res = await getNonstandardCommodityLists({ ...this.page, name: this.name })
      if (res.code === 200) {
        this.goodsList = [...this.goodsList, ...res.data.list]
        this.nextPage = res.data.nextPage
        console.log('goodsList:', this.goodsList);
        if (this.page.pageNum == 1 && this.goodsList.length == 0) {
          uni.showToast({
            title: '没有找到相关商品',
            icon: 'none'
          })
        }
        this.triggered = false
        if (res.data.isLastPage) {
          this.loading = "noMore"
        }
      }
    },
    lower() {
      console.log('222');
      if (this.loading == "noMore") {
        return;
      }
      this.page.pageNum++;
      this.loading = "loading";
      this.getNonstandardCommodityLists()

    },
    searchFn() {
      console.log('1111111');
      if (!this.name) return uni.showToast({
        title: '请输入商品名称',
        icon: 'none'
      })
      this.page.pageNum = 1
      this.goodsList = []
      this.loading = "loading";
      this.getNonstandardCommodityLists()
    },
    clearFn() {
      this.page.pageNum = 1
      this.name = ''
      this.goodsList = []
      this.loading = "loading";
      // this.getNonstandardCommodityLists()
    },
    async addPointPurchase(id) {
      const res = await reqAddPointPurchase({ commodityId: id })
      if (res.code == 200) {
        uni.showToast({
          title: '添加点采成功',
          icon: 'none'
        })
      }
    },
    dianCaiclick() {
      // 跳转页面
      this.$navTo('/pages/procure/noWaitSubmit')
    },
  }
}
</script>
<style>
page {
  background: #f7f7f7;

}
</style>
<style lang="scss" scoped >
.content {
  height: 100vh;
  background-color: #f7f7f7;


}

.topCard {
  font-size: 26rpx;
  line-height: 50rpx;
  height: 80rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20rpx;
  // background-color: #fff;
  border: 1px solid #eee;
}

view {
  box-sizing: border-box;
}

.goodsname {
  font-weight: 600;
}

.goodCard {
  font-size: $uni-font-size-small;
  line-height: 36rpx;
  padding: 20rpx;
  box-sizing: border-box;
  padding-left: 20rpx;

  background-color: #fff;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #f6f6f6;

  .goodsImg {
    width: 220rpx;
    height: 220rpx;
    margin-right: 20rpx;
    border: 1px solid #eee;
    background-color: #f7f7f7;
  }

  .goodInfo {
    height: 220rpx;
    flex: 1;
    display: flex;
    flex-direction: column;
    // justify-content: space-evenly;
    justify-content: space-between;
  }

  .goodsname {
    font-weight: 600;
    width: 300rpx;
    font-size: $uni-font-size-upBase;
    margin-bottom: 10rpx;
  }

  .sub_title {
    font-size: $uni-font-size-mini;
  }

  .flexBox {
    display: flex;
    justify-content: space-between;
    font-size: $uni-font-size-mini;
    // flex: 1;
    line-height: 60rpx;
    width: 100%;
  }

  .btnBox {
    width: 100rpx;
    height: 50rpx;
    line-height: 50rpx;
    border-radius: 10rpx;
    background-color: $uni-main-bgColor;
    text-align: center;
    color: #fff;
  }
}

.floatBox {
  width: 100rpx;
  height: 100rpx;
  line-height: 100rpx !important;
  box-shadow: 0 1px 5px 2px rgba(0, 0, 0, .3);
  font-weight: 600;
  text-align: center;
  border-radius: 50%;
  padding: 10rpx;
  box-sizing: border-box;
}
</style>
